define(function(require, exports, module) {
	var abpdata = require("abpinit");
	var abp = abpdata.abpstart;
	var muiTips = require("muiTips");
	var globalInit = require("globalInit");
	var getJurisdictionList = {
		"getJurisdiction": function(sourceType, myFun, dataModel) {
			var sysOption = {};
			var sysDataModel = {
				"sourceType": sourceType,
				"id": 0
			};
			abp.services.app.sysClientSettingPrice.getModel(sysDataModel, sysOption).
			done(function(data) {
				var overBookType = data.overBookType;
				var option = {};
				if(sourceType == abp.sourceType.SELL) { //销售订单类
					var goodsList = dataModel.sellOutputDetail;
					if(goodsList.length > 0) {
						var sellOutputDetaiList = [];
						for(var i = 0; i < goodsList.length; i++) {
							var sellOutputDetailInput = {
								"goodsId": goodsList[i].goodsId,
								"number": goodsList[i].unitCodeNumber,
								"sourceType": goodsList[i].sourceType,
								"sourceId": goodsList[i].sourceId,
								"sourceItemId": goodsList[i].sourceItemId
							};
							sellOutputDetaiList.push(sellOutputDetailInput);
						}

						var dataModel_1 = {};
						dataModel_1 = sellOutputDetaiList;
						abp.services.app.sellOutput.checkSellNumber(dataModel_1, option).
						done(function(data) {
							if(data) {
								if(overBookType == 2) {
									muiTips.confirmAutoma(" ", "出库数量已经超过订单量，确信要继续提交吗？", 2, function() {
										if(myFun) {
											myFun(dataModel);
										}
									});
									globalInit.buttonReset(".mui-btn-sub");

								} else if(overBookType == 3) {
									muiTips.alertTips(' ', "出库数量不能超过订单量，提交失败！", 3, 3, 'default');
									globalInit.buttonReset(".mui-btn-sub");
								}
							} else {
								globalInit.buttonReset(".mui-btn-sub");
								if(myFun) {
									myFun(dataModel);
								}
							}
						}).fail(function(data) {
							muiTips.alertTips(' ', data.message, 3, 3, "default");
							globalInit.buttonReset(".mui-btn-sub");
						});

					}
				} else if(sourceType == abp.sourceType.BUY) { //采购订单类
					var goodsList = dataModel.buyInputDetail;
					if(goodsList.length > 0) {
						var buyInputDetaiList = [];
						for(var i = 0; i < goodsList.length; i++) {
							var buyInputDetailInput = {
								"goodsId": goodsList[i].goodsId,
								"number": goodsList[i].unitCodeNumber,
								"sourceType": goodsList[i].sourceType,
								"sourceId": goodsList[i].sourceId,
								"sourceItemId": goodsList[i].sourceItemId
							};
							buyInputDetaiList.push(buyInputDetailInput);
						}

						var dataModel_1 = {};
						dataModel_1 = buyInputDetaiList;
						abp.services.app.buyInputList.checkBuyNumber(dataModel_1, option).
						done(function(data) {
							if(data) {
								if(overBookType == 2) {
									muiTips.confirmAutoma(" ", "入库数量已经超过订单量，确信要继续提交吗？", 2, function() {
										if(myFun) {
											myFun(dataModel);
										}
									});
									globalInit.buttonReset(".mui-btn-sub");

								} else if(overBookType == 3) {
									muiTips.alertTips(' ', "入库数量不能超过订单量，提交失败！", 3, 3, 'default');
									globalInit.buttonReset(".mui-btn-sub");
								}
							} else {
								globalInit.buttonReset(".mui-btn-sub");
								if(myFun) {
									myFun(dataModel);
								}
							}
						}).fail(function(data) {
							muiTips.alertTips(' ', data.message, 3, 3, "default");
							globalInit.buttonReset(".mui-btn-sub");
						});

					}
				}

			}).fail(function(data) {
				muiTips.alertTips(' ', data.message, 3, 3, "default");
				globalInit.buttonReset(".mui-btn-sub");
			});
		}
	};
	module.exports = getJurisdictionList;
});